package com.junzhiit.nengji.dao.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.junzhiit.nengji.bo.ShopTechnicianBO;
import com.junzhiit.nengji.dao.ShopTechnicianDAO;
import com.junzhiit.nengji.model.ShopTechnician;
import com.junzhiit.nengji.model.enums.Is;

@Repository
public class ShopTechnicianDAOImpl extends AbstractBaseDAO<ShopTechnician> implements ShopTechnicianDAO {

	@Override
	public List<ShopTechnicianBO> getList(String shopId) {
		StringBuffer sql=new StringBuffer();
		sql.append(" select id,name,position from shop_technician");
		sql.append(" where shop_id=? and is_delete = ?");
		
		StatementParameter param=new StatementParameter();
		param.setString(shopId);
		param.setInt(Is.NO.toIntValue());
		
		return queryForList(sql.toString(), ShopTechnicianBO.class, param);
	}

	@Override
	public List<ShopTechnicianBO> findAll(ShopTechnicianBO shopTechnicianBO,int pageNumber, int maxPageRow) {
		StringBuffer sql=new StringBuffer();
		sql.append(" select * from shop_technician ");
		sql.append(" where shop_id=? and is_delete = ?");
		
		StatementParameter param=new StatementParameter();
		
		param.setString(shopTechnicianBO.getShopId());
		param.setInt(Is.NO.toIntValue());
		
		if(StringUtils.isNotBlank(shopTechnicianBO.getName())){
			sql.append(" and name like ?");
			param.setString("%"+shopTechnicianBO.getName()+"%");
		}
		
		return queryForPagingList(sql.toString(), ShopTechnicianBO.class, param, pageNumber,maxPageRow);
	}

	@Override
	public int getTotalCount(ShopTechnicianBO shopTechnicianBO) {
		StringBuffer sql=new StringBuffer();
		sql.append(" select count(id) from shop_technician ");
		sql.append(" where shop_id=? and is_delete = ?");
		
		StatementParameter param=new StatementParameter();
		
		param.setString(shopTechnicianBO.getShopId());
		param.setInt(Is.NO.toIntValue());
		
		if(StringUtils.isNotBlank(shopTechnicianBO.getName())){
			sql.append(" and name like ?");
			param.setString("%"+shopTechnicianBO.getName()+"%");
		}
		return super.queryForInt(sql.toString(), param);
	}

}
